
from clickFuUtils import cfAction

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from settingZoom import Ui_ZoomSetting

zoomItem="/clickfu/googlemaps/zoom"
zoomDefault=14

class googleMap(cfAction):
    def __init__(self,iface):
        cfAction.__init__(self,self.name(),iface)
        return None
    def tag(self):
        return "googleMap"
    def name(self):
        return "Google Maps"
    def desc(self):
        return "Goto Location on Google Maps"

    def createURL(self,lat,long):
        url = "http://maps.google.com/maps?ll=%s,%s&z=%s" % (lat,long,getZoom())
        return url

def getZoom():
    return QSettings().value(zoomItem,QVariant(zoomDefault)).toInt()[0]
def setZoom(n):
    QSettings().setValue(zoomItem,n)

class googleSettings(QAction):
    def __init__(self,iface):
        QAction.__init__(self,self.name(),iface.mainWindow())
        QObject.connect(self,SIGNAL("triggered()"),self.setMe)
        return None

    def name(self):
        return "Google Maps"

    def setMe(self):
        window=QDialog()
        ui=Ui_ZoomSetting()
        ui.setupUi(window)
        ui.zoomSlider.setInvertedAppearance(False)
        ui.zoomSlider.setRange(1,20)
        ui.valueBox.setRange(1,20)
        ui.zoomSlider.setValue(getZoom())
        if window.exec_():
            setZoom(ui.zoomSlider.value())


